package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.business.domain.AnnualWorkDays;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.IndicatorTow;
import com.ruoyi.business.service.IIndicatorTowService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 指标二Controller
 * 
 * @author ruoyi
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/business/indicatorTow")
public class IndicatorTowController extends BaseController
{
    @Autowired
    private IIndicatorTowService indicatorTowService;

    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:user:import')")
    @PostMapping("/importData")
    @ApiOperation(value = "导入全年出班天数数据", notes = "支持更新已有数据")
    public AjaxResult importData(
            @ApiParam(value = "上传的Excel文件", required = true) MultipartFile file,
            @ApiParam(value = "是否更新已有数据", required = true) boolean updateSupport) throws Exception
    {
        ExcelUtil<IndicatorTow> util = new ExcelUtil<>(IndicatorTow.class);
        List<IndicatorTow> userList = util.importExcel("指标数据二",file.getInputStream(),1);
        String operName = getUsername();
        String message = indicatorTowService.importData(userList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    @ApiOperation(value = "导出全年出班天数数据模板", notes = "提供Excel模板用于导入")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<IndicatorTow> util = new ExcelUtil<>(IndicatorTow.class);
        util.importTemplateExcel(response, "指标数据二","指标数据二");
    }

    /**
     * 查询指标二列表
     */
    @PreAuthorize("@ss.hasPermi('business:IndicatorTow:list')")
    @GetMapping("/list")
    public TableDataInfo list(IndicatorTow indicatorTow)
    {
        startPage();
        List<IndicatorTow> list = indicatorTowService.selectIndicatorTowList(indicatorTow);
        return getDataTable(list);
    }

    /**
     * 导出指标二列表
     */
    @PreAuthorize("@ss.hasPermi('business:IndicatorTow:export')")
    @Log(title = "指标二", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IndicatorTow indicatorTow)
    {
        List<IndicatorTow> list = indicatorTowService.selectIndicatorTowList(indicatorTow);
        ExcelUtil<IndicatorTow> util = new ExcelUtil<IndicatorTow>(IndicatorTow.class);
        util.exportExcel(response, list, "指标二数据");
    }

    /**
     * 获取指标二详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:IndicatorTow:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(indicatorTowService.selectIndicatorTowById(id));
    }

    /**
     * 新增指标二
     */
    @PreAuthorize("@ss.hasPermi('business:IndicatorTow:add')")
    @Log(title = "指标二", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IndicatorTow indicatorTow)
    {
        return toAjax(indicatorTowService.insertIndicatorTow(indicatorTow));
    }

    /**
     * 修改指标二
     */
    @PreAuthorize("@ss.hasPermi('business:IndicatorTow:edit')")
    @Log(title = "指标二", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IndicatorTow indicatorTow)
    {
        return toAjax(indicatorTowService.updateIndicatorTow(indicatorTow));
    }

    /**
     * 删除指标二
     */
    @PreAuthorize("@ss.hasPermi('business:IndicatorTow:remove')")
    @Log(title = "指标二", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(indicatorTowService.deleteIndicatorTowByIds(ids));
    }
}
